package com.psa.element;

import android.content.ContentValues;
import android.database.Cursor;
import com.google.gson.Gson;
import com.psa.tool.DBTool;

/**
 *
 * @author david
 * @date 2014-09-18
 */
public class OperatorCustomer implements IJson,ISqlObject {
    public int Weekday = -1;
    public String DistrictID = "";
    public int SeqNo = -1;
    public String CustomerID = "";

    @Override
    public String toJson() {
        return new Gson().toJson(this);
    }

    @Override
    public int insert(DBTool dbTool) {
        ContentValues values = new ContentValues();
        values.put("Weekday", Weekday);
        values.put("DistrictID", (DistrictID!=null?DistrictID.trim():""));
        values.put("SeqNo", SeqNo);
        values.put("CustomerID", CustomerID.trim());
        return (int)dbTool.insert("OperatorCustomer", values);
    }

    @Override
    public int update(DBTool dbTool) {
        return 0;
    }

    @Override
    public int delete(DBTool dbTool) {
//        String where = "Weekday = ? And Seq = ? And CustomerID = ?";
//        String[] wherevalue = { String.valueOf(Weekday),String.valueOf(Seq),CustomerID };
//        return database.delete("District", where, wherevalue);
        return 0;
    }

    @Override
    public ISqlObject full(Cursor cursor) {
        if (cursor!=null && cursor.moveToNext()) {
            OperatorCustomer operatorCustomer = new OperatorCustomer();
            operatorCustomer.Weekday = cursor.getInt(0);
            operatorCustomer.DistrictID = cursor.getString(1);
            operatorCustomer.SeqNo = cursor.getInt(2);
            operatorCustomer.CustomerID = cursor.getString(3);
            return operatorCustomer;
        }
        return null;
    }

    @Override
    public void clear(DBTool dbTool) {
        dbTool.delete("OperatorCustomer", "Weekday Like ?", new String[]{"%"});
    }

    @Override
    public String getDataSql() {
        return "RouteCustomer";
    }

    @Override
    public String getSyncMethod() {
        return "getdataobjects";
    }
}
